{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "7d2f8c4b",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyboardInterrupt",
     "evalue": "Interrupted by user",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "Input \u001b[1;32mIn [15]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mgetpass\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m hide_card \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mint\u001b[39m(\u001b[43mgetpass\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mgetpass\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mhide_card:\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m)\n\u001b[0;32m      3\u001b[0m count \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m \n\u001b[0;32m      4\u001b[0m \u001b[38;5;66;03m# print(hide_card)\u001b[39;00m\n",
      "File \u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py:1057\u001b[0m, in \u001b[0;36mKernel.getpass\u001b[1;34m(self, prompt, stream)\u001b[0m\n\u001b[0;32m   1050\u001b[0m     \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mwarnings\u001b[39;00m\n\u001b[0;32m   1052\u001b[0m     warnings\u001b[38;5;241m.\u001b[39mwarn(\n\u001b[0;32m   1053\u001b[0m         \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mThe `stream` parameter of `getpass.getpass` will have no effect when using ipykernel\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m   1054\u001b[0m         \u001b[38;5;167;01mUserWarning\u001b[39;00m,\n\u001b[0;32m   1055\u001b[0m         stacklevel\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m2\u001b[39m,\n\u001b[0;32m   1056\u001b[0m     )\n\u001b[1;32m-> 1057\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_input_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m   1058\u001b[0m \u001b[43m    \u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1059\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_parent_ident\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1060\u001b[0m \u001b[43m    \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_parent\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m   1061\u001b[0m \u001b[43m    \u001b[49m\u001b[43mpassword\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m   1062\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\ipykernel\\kernelbase.py:1120\u001b[0m, in \u001b[0;36mKernel._input_request\u001b[1;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[0;32m   1117\u001b[0m             \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[0;32m   1118\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m:\n\u001b[0;32m   1119\u001b[0m     \u001b[38;5;66;03m# re-raise KeyboardInterrupt, to truncate traceback\u001b[39;00m\n\u001b[1;32m-> 1120\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInterrupted by user\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28mNone\u001b[39m\n\u001b[0;32m   1121\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[0;32m   1122\u001b[0m     \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlog\u001b[38;5;241m.\u001b[39mwarning(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid Message:\u001b[39m\u001b[38;5;124m\"\u001b[39m, exc_info\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n",
      "\u001b[1;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
     ]
    }
   ],
   "source": [
    "import getpass\n",
    "hide_card = int(getpass.getpass(\"hide_card:\"))\n",
    "count = 0 \n",
    "# print(hide_card)\n",
    "if hide_card <100 and hide_card>0:\n",
    "    print(\"游戏开始\")\n",
    "    while True:\n",
    "        if count <5:\n",
    "            guess_digit = int(input(\"guess_digit:\")) #玩游戏的人\n",
    "            if guess_digit == hide_card:\n",
    "                print(\"yes ,you got it.\")\n",
    "                break\n",
    "            elif guess_digit > hide_card:\n",
    "                print(\"往小了想想。\")\n",
    "            else:\n",
    "                print(\"往大了猜\")\n",
    "            count = count+1\n",
    "        else:\n",
    "            print(\"猜这么多次都不对，你个笨蛋！\")\n",
    "            print(\"正确答案是：%s\"%hide_card)\n",
    "            break\n",
    "else:\n",
    "    print(\"请输入数字在0-99之间。不要耍赖！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "06561720",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndentationError",
     "evalue": "unindent does not match any outer indentation level (<tokenize>, line 36)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m<tokenize>:36\u001b[1;36m\u001b[0m\n\u001b[1;33m    else:\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m unindent does not match any outer indentation level\n"
     ]
    }
   ],
   "source": [
    "# 1.运行程序后，让用户输入支付宝余额√，然后打印我们的商品列表给用户\n",
    "good_list = [\n",
    "    [\"蜜桃四季春\",6],\n",
    "    [\"柠檬四季春\",4],\n",
    "    [\"草莓波波奶盖\",10],\n",
    "    [\"杨枝甘露\",12],\n",
    "]\n",
    "AliPay = int(input(\"请输入余额：\"))\n",
    "print(\"------------------------------------------蜜雪冰城---------------------------------------------------\")\n",
    "for i in range(4):\n",
    "    print(i,good_list[i][0],str(good_list[i][1])+\"元\")\n",
    "    \n",
    "# 2.让用户输入商品编号√，进行商品的购买√\n",
    "user_choice = int(input(\"请输入商品编号：\"))\n",
    "# 3 用户选择商品后，检查用户的余额是否够√，若够则直接扣款√，不够则提醒用户\n",
    "\n",
    "    if AliPay > good_list[user_choice][1]:\n",
    "                # 余额足够\n",
    "    AliPay = AliPay - good_list[user_choice][1] # 更新用户余额\n",
    "    shopping_list.append(good_list[user_choice])\n",
    "    print(\"购买成功，请等待制作......您的余额还有：%s元\"%(AliPay))\n",
    "    else:\n",
    "        # 余额足够\n",
    "    AliPay = AliPay - good_list[user_choice][1] # 更新用户余额\n",
    "    shopping_list.append(good_list[user_choice])\n",
    "    print(\"购买成功，请等待制作...您的余额还有：%s元\"%(AliPay))\n",
    "    else:\n",
    "            #余额不够\n",
    "    print(\"您的余额不足\"+str(good_list[user_choice][1])+\"元，请更换支付方式或者选择其他商品，欢迎再来尝试\")\n",
    "        # 3.2 用户输入其他\n",
    "elif user_choice == \"q\":\n",
    "        print(\"感谢您的购买，欢迎下次光临\")\n",
    "        print(\"您的购物车：\",shopping_list)\n",
    "        print(\"您的余额还有：\",AliPay)\n",
    "        break\n",
    "IndentationError: unindent does not match any outer indentation level\n",
    "\n",
    "    else:\n",
    "        print(\"您输入的商品不存在或者您输入的内容有误\")\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "59ea8820",
   "metadata": {},
   "outputs": [],
   "source": [
    "product_list = [\n",
    "    [\"蜜雪柠檬水\",6],\n",
    "    [\"蜜桃四季春\",10],\n",
    "    [\"芒果奶盖\",12],\n",
    "    [\"葡萄波波奶茶\",8]\n",
    "]\n",
    "shopping_car =[]\n",
    "AliPay = int(input(\"请输入余额：\"))\n",
    "while True:\n",
    "    print(\"----------商品列表----------\")\n",
    "    for i in range(4):\n",
    "        print(\"商品序号\",\"(\"+str(i)+\")：\",product_list[i][0],str(product_list[i][1])+\"元\")  # 格式化输出\n",
    "    # 2. 让用户输入商品编号进行商品的购买。:直接用商品列表的 index 作为商品标号\n",
    "    user_choice = input(\"请输入商品编号：\")\n",
    "    # 情景1：用户正在购买，输入商品编号\n",
    "    if user_choice.isdigit():\n",
    "        # 情景一：余额大于商品价格\n",
    "        if AliPay >= product_list[int(user_choice)][1]:\n",
    "            AliPay = AliPay - product_list[int(user_choice)][1]\n",
    "            shopping_car.append(product_list[int(user_choice)])   \n",
    "            print(\"商品购买成功，正在制作中...您的余额还有%s元\"%(AliPay))\n",
    "        # 情景二：余额小于商品价格\n",
    "        else:\n",
    "            print(\"您的余额不足，请更换支付方式~~~\")\n",
    "    # 情景2：用户输入退出，结束购买\n",
    "    elif user_choice == \"q\":\n",
    "        print(\"您已购买的商品：\",shopping_car)  \n",
    "        print(\"您的余额还有%s,欢迎下次光临~~\"%(AliPay)) \n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8c621b41",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
